/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package poker;

import prop.Carta;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.io.Serializable;
import java.util.Vector;

/**
 *
 * @author pol
 */
public class AreaDibujoDescarte extends AreaDibujo implements Serializable {
    private Ventana vent;
    private Vector vCartas;
    private boolean[] cartaDescartada;
    private String nombreJug;
    
    public AreaDibujoDescarte(Ventana ven, Vector vect, String nombre) {
        vent = ven;
        vCartas = vect;
        nombreJug = nombre;
        int n = vCartas.size();
        cartaDescartada = new boolean[n];
        for (int i = 0; i < n; ++i) {
            cartaDescartada[i] = false;
            /*System.err.println("Carta #" + i + " " +
                    ((Carta)vCartas.get(i)).getPalo().toString() + " " +
                    ((Carta)vCartas.get(i)).getNum());*/
        }
        repaint();
    }
    
    private void finalizarDescarte() {
        int n = vCartas.size();
        Vector v = new Vector<Carta>(0);
        for (int i = n - 1; i >= 0; --i)
            if (cartaDescartada[i]) v.add(vCartas.get(i));
        repaint();
        vent.finalizarDescarte(v);
    }

    @Override
    public void clickRecibido(int x, int y) {
        if (x >= 180 && x <= 180 + 250 && y >= 430 && y <= 430 + 30)
            finalizarDescarte();
        int n = vCartas.size();
        for (int i = 0; i < n; ++i) {
            int x1 = 90 + 95*i;
            int x2 = x1 + 90;
            int y1 = 280;
            int y2 = y1 + 130;
            if (cartaDescartada[i]) y1 -= 50;
            if (x >= x1 && x <= x2 && y >= y1 && y <= y2)
                cartaDescartada[i] = !cartaDescartada[i];
        }
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        pintaFondo(g);
        g.setColor(new Color(0, 64, 0));
        g.fillRect(180, 430, 250, 30);
        g.setColor(new Color(255, 255, 0));
        g.setFont(new Font(null, Font.BOLD, 15));
        g.drawString(nombreJug + ", te toca descartar", 90, 90);
        g.drawString("ESTOY LISTO", 250, 450);
        int n = vCartas.size();
        for (int i = 0; i < n; ++i) {
            Carta c = (Carta) vCartas.get(i);
            int x = 90 + 95*i;
            int y = 280;
            if (cartaDescartada[i]) y -= 50;
            pintaCarta(x, y, c, g);
        }
    }
}
